package net.phoenix.repository.property;

import java.io.InputStream;
import java.util.Calendar;

import javax.jcr.Binary;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.nodetype.PropertyDefinition;

import net.phoenix.repository.BasicNode;
import net.phoenix.repository.value.BinaryValue;
import net.phoenix.repository.value.BooleanValue;
import net.phoenix.repository.value.DateValue;
import net.phoenix.repository.value.DoubleValue;
import net.phoenix.repository.value.LongValue;
import net.phoenix.repository.value.ReferenceValue;

/**
 * 
 * Jigsaw server
 * 
 * @author <a href="shamphone@gmail.com">Li XiongFeng</a>
 * @date 2012-1-3
 * @version 1.0.0
 */
public class StringProperty extends BasicProperty {
	/**
	 * create single value property
	 * 
	 * @param node
	 * @param definition
	 * @param value
	 */
	public StringProperty(BasicNode node, PropertyDefinition definition, Value value) {
		super(node, definition, value);

	}

	/**
	 * create multiple values property
	 * 
	 * @param node
	 * @param definition
	 * @param values
	 */
	public StringProperty(BasicNode node, PropertyDefinition definition, Value[] values) {
		super(node, definition, values);
	}

	/**
	 * create a property with default value;
	 * 
	 * @param node
	 * @param definition
	 */
	public StringProperty(BasicNode node, PropertyDefinition definition) {
		super(node, definition);

	}
	

	@Override
	public void setValue(String value) throws RepositoryException {
		this.setValue(this.getValueFactory().createValue(value));
	}

	@Override
	public void setValue(Calendar value) throws RepositoryException {
		this.setValue(new DateValue(value).getString());
	}

	@Override
	public void setValue(Binary value) throws RepositoryException {		
		this.setValue(new BinaryValue(value).getString());
	}

	@Override
	public void setValue(InputStream value) throws RepositoryException {
		this.setValue(new BinaryValue(value).getString());
	}

	@Override
	public void setValue(long value) throws RepositoryException {
		this.setValue(new LongValue(value).getString());
	}

	@Override
	public void setValue(Node value) throws RepositoryException {
		this.setValue(new ReferenceValue(value).getString());
	}

	@Override
	public void setValue(double value) throws RepositoryException {
		this.setValue(new DoubleValue(value).getString());
	}

	@Override
	public void setValue(boolean value) throws RepositoryException {
		this.setValue(new BooleanValue(value).getString());
	}
	

	
}
